package cc.shacocloud.kotlin.tools.amqp

import com.rabbitmq.client.ConnectionFactory
import com.rabbitmq.client.impl.AMQConnection

/**
 * amqp 配置
 * @author 思追(shaco)
 */
data class AmqpProperties(
    val virtualHost: String = ConnectionFactory.DEFAULT_VHOST,
    val host: String = ConnectionFactory.DEFAULT_HOST,
    val port: Int = ConnectionFactory.USE_DEFAULT_PORT,
    val username: String = ConnectionFactory.DEFAULT_USER,
    val password: String = ConnectionFactory.DEFAULT_PASS,
    val requestedChannelMax: Int = ConnectionFactory.DEFAULT_CHANNEL_MAX,
    val requestedFrameMax: Int = ConnectionFactory.DEFAULT_FRAME_MAX,
    val requestedHeartbeat: Int = ConnectionFactory.DEFAULT_HEARTBEAT,
    val connectionTimeout: Int = ConnectionFactory.DEFAULT_CONNECTION_TIMEOUT,
    val handshakeTimeout: Int = ConnectionFactory.DEFAULT_HANDSHAKE_TIMEOUT,
    val shutdownTimeout: Int = ConnectionFactory.DEFAULT_SHUTDOWN_TIMEOUT,
    val clientProperties: MutableMap<String, Any> = AMQConnection.defaultClientProperties()
) {

    /**
     * 获取当前配置的链接工厂
     */
    fun getConnectionFactory(): ConnectionFactory {
        val factory = ConnectionFactory()
        factory.virtualHost = virtualHost
        factory.host = host
        factory.port = port
        factory.username = username
        factory.password = password
        factory.requestedChannelMax = requestedChannelMax
        factory.requestedFrameMax = requestedFrameMax
        factory.requestedHeartbeat = requestedHeartbeat
        factory.connectionTimeout = connectionTimeout
        factory.handshakeTimeout = handshakeTimeout
        factory.shutdownTimeout = shutdownTimeout
        factory.clientProperties = clientProperties
        return factory
    }

}
